home *** CD-ROM | disk | FTP | other *** search
/ Aminet 19 / Aminet 19 (1997)(GTI - Schatztruhe)[!][Jun 1997].iso / Aminet / dev / gui / MPGui5xs.lha / sg / Hook.c next >
C/C++ Source or Header  |  1997-03-04  |  6KB  |  208 lines

  1. // MPGui - requester library
  2. // Copyright (C) © 1995 Mark John Paddock
  3.  
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; either version 2 of the License, or
  7. // any later version.
  8.  
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. // GNU General Public License for more details.
  13.  
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. // mark@topic.demon.co.uk
  19. // mpaddock@cix.compulink.co.uk
  20.  
  21. #include <proto/exec.h>
  22. #include <clib/graphics_protos.h>
  23. #include <graphics/gfxmacros.h>
  24. #define GfxBase MyGfxBase
  25. #include <pragmas/graphics_pragmas.h>
  26. #include <dos/dos.h>
  27. #include <clib/gadtools_protos.h>
  28. #define GadToolsBase MyGadToolsBase
  29. #include <pragmas/gadtools_pragmas.h>
  30. #include <libraries/gadtools.h>
  31. #include <string.h>
  32. #include <proto/locale.h>
  33. extern struct Library *LocaleBase = NULL;
  34. #include "MPGui.h"
  35. #define CATCOMP_NUMBERS
  36. #include "messages.h"
  37.  
  38. ULONG __asm HookEntryList(register __a0 struct Hook *Hook,
  39.                                  register __a2 struct MyValue *MyValue,
  40.                                  register __a1 struct LVDrawMsg *msg);
  41.  
  42. ULONG __asm MyRefresh(register __a0 struct Hook *hook,
  43.                                   register __a2 struct FileRequester *fr,
  44.                                   register __a1 struct IntuiMessage *msg);
  45.  
  46. static far int OpenCount = 0;
  47. far struct Hook HookList = {0};
  48. far struct GfxBase *MyGfxBase = NULL;
  49. far struct Library *MyGadToolsBase = NULL;
  50.  
  51. char OKCHAR;
  52. char CANCELCHAR;
  53. char SAVECHAR;
  54. char USECHAR;
  55.  
  56. int __stdargs
  57. _STI_Open(void) {
  58.     Forbid();
  59.     if (!OpenCount) {
  60.         ++OpenCount;
  61.         Permit();
  62.         HookList.h_Entry = (ULONG (*)())HookEntryList;
  63.         HookList.h_Data     = NULL;
  64.         GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
  65.         if (!GfxBase) {
  66. //            Permit();
  67.             return 1;
  68.         }
  69.         GadToolsBase = OpenLibrary("gadtools.library",0);
  70.         if (!GadToolsBase) {
  71.             CloseLibrary((struct Library *)GfxBase);
  72.             GfxBase = NULL;
  73. //            Permit();
  74.             return 1;
  75.         }
  76.     }
  77.     else {
  78.         ++OpenCount;
  79.         Permit();
  80.     }
  81.     if (!(LocaleBase = OpenLibrary("locale.library",38))) {
  82.         return 1;
  83.     }
  84.     Catalog = OpenCatalog(NULL,
  85.                                 "mp/mpgui.catalog",
  86.                                 TAG_END);
  87.     OKCHAR = *GetMessage(MSG_OKCHAR);
  88.     USECHAR = *GetMessage(MSG_USECHAR);
  89.     SAVECHAR = *GetMessage(MSG_SAVECHAR);
  90.     CANCELCHAR = *GetMessage(MSG_CANCELCHAR);
  91.     return 0;
  92. }
  93.  
  94. void __stdargs
  95. _STD_Close(void) {
  96.     --OpenCount;
  97.     if (!OpenCount) {
  98.         if (GfxBase) {
  99.             CloseLibrary((struct Library *)GfxBase);
  100.             GfxBase = NULL;
  101.         }
  102.         if (GadToolsBase) {
  103.             CloseLibrary(GadToolsBase);
  104.             GadToolsBase = NULL;
  105.         }
  106.         if (LocaleBase) {
  107.             CloseCatalog(Catalog);
  108.             Catalog = NULL;
  109.             CloseLibrary(LocaleBase);
  110.             LocaleBase = NULL;
  111.         }
  112.     }
  113.     return;
  114. }
  115.  
  116. ULONG __asm MyRefresh(register __a0 struct Hook *hook,
  117.                                   register __a2 struct FileRequester *fr,
  118.                                   register __a1 struct IntuiMessage *msg) {
  119.     if (msg->Class == IDCMP_REFRESHWINDOW) {
  120.         GT_BeginRefresh(((struct MPGuiHandle *)hook->h_Data)->Window);
  121.         GT_EndRefresh(((struct MPGuiHandle *)hook->h_Data)->Window,TRUE);
  122.     }
  123.     return 0;
  124. }
  125.  
  126. ULONG __asm HookEntryList(register __a0 struct Hook *Hook,
  127.                                  register __a2 struct MyValue *MyValue,
  128.                                  register __a1 struct LVDrawMsg *msg) {
  129.     char buffer[2];
  130.     ULONG len;
  131.     WORD length;
  132.     struct TextExtent textExtent;
  133.     if (msg->lvdm_MethodID != LV_DRAW) {
  134.         return LVCB_UNKNOWN;
  135.     }
  136.     switch(msg->lvdm_State) {
  137.     case LVR_NORMAL:
  138.     case LVR_NORMALDISABLED:
  139.     case LVR_SELECTED:
  140.     case LVR_SELECTEDDISABLED:
  141.         Move(msg->lvdm_RastPort,msg->lvdm_Bounds.MinX,msg->lvdm_Bounds.MinY+msg->lvdm_RastPort->TxBaseline);
  142.         length = TextLength(msg->lvdm_RastPort,"+",1);
  143.         switch(msg->lvdm_State) {
  144.         case LVR_NORMAL:
  145.         case LVR_NORMALDISABLED:
  146.             buffer[0] = ' ';
  147.             break;
  148.         case LVR_SELECTED:
  149.         case LVR_SELECTEDDISABLED:
  150.             buffer[0] = '+';
  151.             break;
  152.         }
  153.         buffer[1]=0;
  154.         len = TextFit(msg->lvdm_RastPort,MyValue->VNode.ln_Name,strlen(MyValue->VNode.ln_Name),&textExtent,NULL,1,msg->lvdm_Bounds.MaxX-msg->lvdm_Bounds.MinX+1-length,32767);
  155.         if (!MyValue->Selected) {
  156.             SetABPenDrMd(msg->lvdm_RastPort,msg->lvdm_DrawInfo->dri_Pens[TEXTPEN],msg->lvdm_DrawInfo->dri_Pens[BACKGROUNDPEN],JAM2);
  157.         }
  158.         else {
  159.             SetABPenDrMd(msg->lvdm_RastPort,msg->lvdm_DrawInfo->dri_Pens[FILLTEXTPEN],msg->lvdm_DrawInfo->dri_Pens[FILLPEN],JAM2);
  160.         }
  161.         Text(msg->lvdm_RastPort,buffer,1);
  162.         if (msg->lvdm_RastPort->cp_x < msg->lvdm_Bounds.MinX+length) {
  163.             if (!MyValue->Selected) {
  164.                 SetAPen(msg->lvdm_RastPort,msg->lvdm_DrawInfo->dri_Pens[BACKGROUNDPEN]);
  165.             }
  166.             else {
  167.                 SetAPen(msg->lvdm_RastPort,msg->lvdm_DrawInfo->dri_Pens[FILLPEN]);
  168.             }
  169.             RectFill(msg->lvdm_RastPort,msg->lvdm_RastPort->cp_x,msg->lvdm_Bounds.MinY,msg->lvdm_Bounds.MinX-1+length,msg->lvdm_Bounds.MaxY);
  170.         }
  171.         Move(msg->lvdm_RastPort,msg->lvdm_Bounds.MinX+length,msg->lvdm_Bounds.MinY+msg->lvdm_RastPort->TxBaseline);
  172.         if (!MyValue->Selected) {
  173.             SetABPenDrMd(msg->lvdm_RastPort,msg->lvdm_DrawInfo->dri_Pens[TEXTPEN],msg->lvdm_DrawInfo->dri_Pens[BACKGROUNDPEN],JAM2);
  174.         }
  175.         else {
  176.             SetABPenDrMd(msg->lvdm_RastPort,msg->lvdm_DrawInfo->dri_Pens[FILLTEXTPEN],msg->lvdm_DrawInfo->dri_Pens[FILLPEN],JAM2);
  177.         }
  178.         Text(msg->lvdm_RastPort,MyValue->VNode.ln_Name,len);
  179.         if (!MyValue->Selected) {
  180.             SetAPen(msg->lvdm_RastPort,msg->lvdm_DrawInfo->dri_Pens[BACKGROUNDPEN]);
  181.         }
  182.         else {
  183.             SetAPen(msg->lvdm_RastPort,msg->lvdm_DrawInfo->dri_Pens[FILLPEN]);
  184.         }
  185.         RectFill(msg->lvdm_RastPort,msg->lvdm_RastPort->cp_x,msg->lvdm_Bounds.MinY,msg->lvdm_Bounds.MaxX,msg->lvdm_Bounds.MaxY);
  186.         break;
  187.     default:
  188.         break;
  189.     }
  190.     switch(msg->lvdm_State) {
  191.     case LVR_NORMALDISABLED:
  192.     case LVR_SELECTEDDISABLED:
  193.         {
  194.             USHORT ditherdata[] = {
  195.                 0x4444,
  196.                 0x1111
  197.             };
  198.             SetAfPt(msg->lvdm_RastPort,ditherdata,1);
  199.             SetABPenDrMd(msg->lvdm_RastPort,msg->lvdm_DrawInfo->dri_Pens[TEXTPEN],msg->lvdm_DrawInfo->dri_Pens[TEXTPEN],JAM1);
  200.             RectFill(msg->lvdm_RastPort,msg->lvdm_Bounds.MinX,msg->lvdm_Bounds.MinY,msg->lvdm_Bounds.MaxX,msg->lvdm_Bounds.MaxY);
  201.         }
  202.         break;
  203.     default:
  204.         break;
  205.     }
  206.     return LVCB_OK;
  207. }
  208.